import request from "@/utils/request";
import httpRequest from "@/utils/requestUtil";
import { IObject } from "@/api/common/common";
import { ContractItem } from "./contract.api";

const CONTRACT_SCORE_BASE_URL = "/business/contractScore";

const ContractScoreAPI = {
  /** 获取分页数据 */
  getPage(queryParams?: ContractScorePageQuery) {
    return httpRequest.get<PageResult<ContractScorePageVO[]>>(
      `${CONTRACT_SCORE_BASE_URL}/loadPage`,
      queryParams
    );
  },





  /**
   * 评分
   * @param params 
   * @returns
   */
  review(params: ContractScorePageVO) {
    return httpRequest.post<boolean>(
      `${CONTRACT_SCORE_BASE_URL}/review`,
      params
    );
  },

 


  loadByContractId(id: string) {
    return request<any, ContractScorePageVO>({
      url: `${CONTRACT_SCORE_BASE_URL}/loadContractId?contractId=${id}`,
      method: "get",
    });
  },
};

export default ContractScoreAPI;

/** 分页查询参数 */
export interface ContractScorePageQuery extends PageQuery {

}

/** 分页对象 */
export interface ContractScorePageVO {
  id?: string;
  /** 合同id */
  contractId?: string;
  /** 合同名称 */
  contractName?: string;
  /** 负责人id */
  majorUserId?:string;
  /** 负责人名称 */
  majorUsername?: string;
  /** 负责人得分 */
  majorScore?:number;
  /** 负责人评价 */
  majorRemark?: string;
  /** 设计师id */
  designerId?: string;
  /** 设计师名称 */
  designerName?: string;
  /** 设计得分 */
  designerScore?:number;
  /** 设计师评价 */
  designerRemark?: string;
  /** 合同得分 */
  contractScore?: number;
  /** 合同评价 */
  contractRemark?: string;
  /** 审核人id */
  reviewUserId?: string;
  /** 审核人名称 */
  reviewUserName?: string;
  /** 状态 0 未评价，1已评价 */
  status?:number;
  /** 评价时间 */
  reviewTime?: string;
  /** 合同任务节点评价 */
  contractNodeScoreVos: ContractNodeScore[];
}

export interface ContractNodeScore {
  id?: string;
  /** 合同id */
  contractId?: string;
  /** 合同评价id */
  contractScoreId?:string;
  /** 节点id */
  nodeId?: string;
  /** 节点名称 */
  nodeName?: string;
  /** 节点得分 */
  score?: number;
  /** 节点评价 */
  remark?: string;
  /** 节点任务项及人员评价 */
  contractUserScores: ContractUserScore[];

}

export interface ContractUserScore {
  id?: string;
  /** 合同id */
  contractId?: string;
  /** 合同任务节点评价id */
  contractNodeScoreId?: string;
  /** 人员id */
  userId?: string;
  /** 人员名称 */
  username?: string;
  /** 节点任务项及人员得分 */
  score?: number;
  /** 节点任务项及人员评价 */
  remark?: string;
  /**考核，得分项/任务名称 */
  name?: string;
}


export interface ContractDesignForm {
  /** 合同id */
  id?: string;
  items?: ContractItem[];
}

export enum ContractDesignStatus {
  WAIT_DISPATCH = "WAIT_DISPATCH",
  DESIGNING = "DESIGNING",
  CONFIRM = "CONFIRM",
}

export const ContractDesign_Status_Label: IObject = {
  [ContractDesignStatus.WAIT_DISPATCH]: "待派单",
  [ContractDesignStatus.DESIGNING]: "设计中",
  [ContractDesignStatus.CONFIRM]: "已确认",
};
